# -.- coding: utf-8 -.-

#from profiles.models import *
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

from django.conf import settings
from django.core.files.storage import FileSystemStorage
from os import path

fs = FileSystemStorage(location=settings.BASE_DIR)

def crea_path (instance, filename):
    import string
    valid_chars = "-_.()%s%s" % (string.ascii_letters, string.digits)
    usr = ''.join(c for c in instance.proyecto.usuario.username if c in valid_chars)
    tit = ''.join(c for c in instance.proyecto.nombre if c in valid_chars)
    nuevonombre = usr+os.path.splitext(filename)[-1]
    p = path.join("profiles", usr, nuevonombre)
    return p

class UserProfile(Models.Model):
    """
        
    """
    class Meta:
        abstract = True
    
    user = models.ForeignKey(User, unique=True, related_name="%(class)s_related")
    descripcion = models.TextField(blank=True, null=True)
    foto = models.FileField(_(u'Foto de perfil'), upload_to = crea_path)
     
    def __unicode__(self):
        return self.user

